<template>
  <div class="department-container">
    <!-- 搜索和操作区域 -->
    <div class="header-container">
      <el-form :inline="true" :model="searchForm" class="search-form">
        <el-form-item label="部门名称">
          <el-input
              v-model="searchForm.departmentName"
              placeholder="请输入部门名称"
              clearable
              @clear="handleSearch"
          />
        </el-form-item>
        <el-form-item label="部门编号">
          <el-input
              v-model="searchForm.departmentCode"
              placeholder="请输入部门编号"
              clearable
              @clear="handleSearch"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">搜索</el-button>
          <el-button @click="resetSearch">重置</el-button>
        </el-form-item>
      </el-form>

      <div class="operation-buttons">
        <el-button type="primary" @click="handleCreate">新增部门</el-button>
        <el-button type="success" @click="exportDepartmentList">导出</el-button>
      </div>
    </div>

    <!-- 部门表格 -->
    <el-table
        :data="tableData"
        border
        stripe
        v-loading="loading"
        style="width: 100%"
        @sort-change="handleSortChange"
    >
      <el-table-column prop="departmentId" label="部门ID" width="100" sortable="custom" />
      <el-table-column prop="departmentCode" label="部门编号" width="150" />
      <el-table-column prop="departmentName" label="部门名称" width="180" />
      <el-table-column prop="departmentStaffNumber" label="当前人数" width="120" align="center" />
      <el-table-column prop="departmentHistoryStaffNumber" label="历史人数" width="120" align="center" />
      <el-table-column prop="remarks" label="备注" show-overflow-tooltip />

<!--      <el-table-column fixed="right" label="操作" width="180" align="center">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" @click="handleEdit(scope.row)">编辑</el-button>-->
<!--          <el-button link type="danger" @click="handleDelete(scope.row)">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <!-- 分页组件 -->
    <div class="pagination-container">
      <el-pagination
          v-model:current-page="pagination.current"
          v-model:page-size="pagination.size"
          :page-sizes="[10, 20, 50, 100]"
          :total="pagination.total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>

    <!-- 新增/编辑对话框 -->
    <el-dialog
        v-model="dialogVisible"
        :title="dialogTitle"
        width="600px"
        :close-on-click-modal="false"
    >
      <department-form
          v-if="dialogVisible"
          :form-data="currentDepartment"
          @submit="handleSubmit"
          @cancel="dialogVisible = false"
      />
    </el-dialog>
  </div>
</template>
<style scoped src="../../assets/style/DepartmentList.css"></style>
<script src="../../script/department/DepartmentList.js"></script>